<template>
  <div class="e-radio">
    <a-radio-group v-model:value="value" :disabled="disabled" @change="handleChange">
      <a-radio v-for="option in options" :key="option.value" :value="option.value">{{ option.text }}</a-radio>
    </a-radio-group>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
const props = defineProps({
  options: {
    type: Array,
    default() {
      return []
    }
  },
  modelValue: {
    type: [Number, String, Boolean],
    default: 0
  },
  disabled: {
    type: Boolean,
    default: false
  }
})
const value = ref(props.modelValue)
watch(
  () => props.modelValue,
  val => {
    value.value = val
  }
)
const emits = defineEmits(['update:modelValue', 'change'])
const handleChange = () => {
  emits('change', value.value)
  emits('update:modelValue', value.value)
}
</script>

<style lang="less" scoped>
.e-radio {
  width: 100%;
  height: 32px;
  border: 1px solid #e1e6f0;
  display: flex;
  justify-content: center;
  align-items: center;
  .ant-radio-group {
    width: 100%;
    display: flex;
    justify-content: space-around;
    .ant-radio-wrapper {
      height: 100%;
      flex: 1;
      padding-left: 8px;
      border-right: 1px solid #e1e6f0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      &:last-child {
        border-right: none;
      }
    }
  }
}
</style>
